package com.zhang.management;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.table.DefaultTableModel;

import com.zhang.bean.Course;
import com.zhang.bean.SC;

import zhang.jdbc.graph.Student;
import zhang.utils.JDBCUtils;

import javax.swing.JLabel;
import java.awt.Font;
import java.util.Iterator;
import java.util.List;

import javax.swing.JTable;
import javax.swing.JScrollPane;

public class XueShengChengJiDan extends JFrame {

	private JPanel contentPane;
	private JTable table;
	private JLabel tname;
	private JLabel tphone;
	private JLabel showLab;
	private Student stu_;
	private JDBCUtils jdb = new JDBCUtils();
	private DefaultTableModel mode;
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					XueShengChengJiDan frame = new XueShengChengJiDan();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public XueShengChengJiDan(Student stu) {
		this();
		stu_=stu;
		System.out.println(stu_);
		tname.setText(stu.getname());
		tphone.setText(stu.getSiphone());
		showLab.setText(stu.getname()+"同学成绩单");
		List<SC> selectAll = jdb.selectAll(SC.class);
		Iterator<SC> it =selectAll.iterator();
		Student tmp;
		SC t;
		Course cou;
		//把集合里面选择对应课程的学生更新到表格
		while(it.hasNext()) {
			t=it.next();
			
			tmp =jdb.selectOne(Student.class, t.getId());
			if(tmp.getSid()==stu_.getSid())
			mode.addRow(new String[] {tmp.getname(),t.getUsual_grade()+"",t.getExam_grade()+"",t.getFinal_grade()+"",t.getComment()});
		}
	}
	public XueShengChengJiDan() {
		setDefaultCloseOperation(JFrame.TEXT_CURSOR);
		setBounds(100, 100, 841, 427);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblNewLabel = new JLabel("学生成绩单汇总");
		lblNewLabel.setFont(new Font("黑体", Font.PLAIN, 32));
		lblNewLabel.setBounds(280, 10, 283, 56);
		contentPane.add(lblNewLabel);
		
		JLabel lblNewLabel_1 = new JLabel("姓名");
		lblNewLabel_1.setBounds(89, 77, 58, 15);
		contentPane.add(lblNewLabel_1);
		
		tname = new JLabel("");
		tname.setBounds(176, 77, 58, 15);
		contentPane.add(tname);
		
		JLabel lblNewLabel_3 = new JLabel("电话");
		lblNewLabel_3.setBounds(290, 77, 58, 15);
		contentPane.add(lblNewLabel_3);
		
		tphone = new JLabel("");
		tphone.setBounds(406, 76, 157, 15);
		contentPane.add(tphone);
		
		showLab = new JLabel("");
		showLab.setBounds(392, 128, 138, 15);
		contentPane.add(showLab);
		
		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(89, 189, 665, 122);
		contentPane.add(scrollPane);
		
		table = new JTable();
		mode = new DefaultTableModel(new Object[][] {},new String[] {"姓名","科目","平时成绩","期末成绩","最后成绩"});
		table.setModel(mode);
		scrollPane.setViewportView(table);
		
		this.setVisible(true);
	}
}
